package com.cooltool.component;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;

public class AccordionItem extends JComponent{

	private String title;
	
	private Image img;
	
	private JPanel titlePanel;
	
	private Component content;
	
	public AccordionItem(Image img, String title, Component content){
		this.img = img;
		this.title = title;
		this.content = content;
		initTitlePanel();
		init();
	}
	
	public JPanel getTitlePanel() {
		return titlePanel;
	}

	public AccordionItem(Image img, String title, JPanel titlePanel, Component content){
		this.img = img;
		this.title = title;
		this.titlePanel = titlePanel;
		this.content = content;
		
		init();
	}
	
	protected void setTitleHeight(int height){
		titlePanel.setPreferredSize(new Dimension(titlePanel.getWidth(), height));
	}
	
	private void initTitlePanel(){
		this.titlePanel = new JPanel();
		titlePanel.setLayout(new BorderLayout());
		JLabel jl = new JLabel();
		jl.setFont(new Font("",Font.PLAIN,12));
		if(title != null)jl.setText(title);
		if(img != null)jl.setIcon(new ImageIcon(img));
		titlePanel.add(jl);
		titlePanel.setBorder(new BevelBorder(BevelBorder.RAISED));
	}
	
	private void init(){
		this.setLayout(new BorderLayout());
		this.add(titlePanel,BorderLayout.NORTH);
		this.add(content);
	}
}
